/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.emocbc;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;

/**
 *
 * @author GiangLT
 */
public class TextFileFilter {

    public static void main(String[] args) {
        try {
            File file = new File("F:\\Projects\\DailyInfo\\test\\log smscb.TXT");
            List<String> lines = FileUtils.readLines(file);
            Predicate<String> predicate = new Predicate<String>() {

                @Override
                public boolean apply(String input) {
                    return input.contains("data");
                }
            };
            Collection<String> filteredLines = Collections2.filter(lines, predicate);

            
            Function<String, String> function = new Function<String, String>() {

                @Override
                public String apply(String input) {
//                    System.out.println("Input: " + input);
                    int index = input.lastIndexOf("data");
                    String data = input.substring(index + 6, input.length() - 1);
//                    System.out.println(data);
                    return data;
                }
            };
            Collection<String> transformedLines = Collections2.transform(filteredLines, function);
            System.out.println("End transform");

            Set<String> set = new LinkedHashSet<String>();
            set.addAll(transformedLines);
            List<String> distinctList = Lists.newArrayList(set);
            Collections.sort(distinctList);
            for (String string : distinctList) {
                System.out.println(string);
            }
        } catch (IOException ex) {
            Logger.getLogger(TextFileFilter.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
